  
#include "hw_config.h"
#include "led.h"
#include "key.h"

static volatile u8 s_key = 0;
static volatile u8 s_exit = 0;

void gpio_polling_key(void)
{
	s_exit = 0;

	while(!s_exit)
	{

		if( !inp(USER_KEY1_PIN, USER_KEY1_PIN_NO) && !(s_key & KEY_KEY1) )
		{
			// usart_puts("Key1 Pressed.\r\n");
			bsp_led_core_on(ledUserCore);
			s_key |= KEY_KEY1;
		}
		else if( inp(USER_KEY1_PIN, USER_KEY1_PIN_NO) && (s_key & KEY_KEY1) )
		{
			//usart_puts("Key1 Released.\r\n");
			bsp_led_core_off(ledUserCore);
			s_key &= ~KEY_KEY1;
		}
		if( !inp(USER_KEY2_PIN, USER_KEY2_PIN_NO) && !(s_key & KEY_KEY2) )
		{
			//usart_puts("Key2 Pressed.\r\n");
			bsp_led_bottom_on(ledUserBottom1);
			s_key |= KEY_KEY2;
		}
		else if( inp(USER_KEY2_PIN, USER_KEY2_PIN_NO) && (s_key & KEY_KEY2) )
		{
			//usart_puts("Key2 Released.\r\n");
			bsp_led_bottom_off(ledUserBottom1);
			s_key &= ~KEY_KEY2;
		}
		if( !inp(USER_KEY3_PIN, USER_KEY3_PIN_NO) && !(s_key & KEY_KEY3) )
		{
			//usart_puts("Key3 Pressed.\r\n");
			bsp_led_core_on(ledUserCore);
			s_key |= KEY_KEY3;
		}
		else if( inp(USER_KEY3_PIN, USER_KEY3_PIN_NO) && (s_key & KEY_KEY3) )
		{
			//usart_puts("Key3 Released.\r\n");
			bsp_led_core_off(ledUserCore);
			s_key &= ~KEY_KEY3;
		}

		_delay_ms(20);
	}

}

void main(void)
{
	bsp_led_gpio_init();
	bsp_key_gpio_init();

	gpio_polling_key();

	while(1)
	{

	}

}
